package com.zkx.fssb.controller.admin;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zkx.fssb.domain.dto.OrderDto;
import com.zkx.fssb.domain.po.Orders;
import com.zkx.fssb.result.Result;
import com.zkx.fssb.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@Slf4j
@RestController
@RequestMapping("/admin/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 查询所有订单
     * @return
     */
    @GetMapping
    public Result<List<Orders>>  getAllOrders(){
        List<Orders> ordersList = orderService.list();
        return Result.success(ordersList);
    }




    /**
     * 订单分页
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    public Result<Page> page(Integer pageNo,Integer pageSize){

        Page<Orders> pageInfo = new Page(pageNo,pageSize);
        orderService.page(pageInfo);
        return Result.success(pageInfo);

    }

    /**
     * 新建订单
     * @param orderDto
     * @return
     */
    @PostMapping
    public Result saveOrder(@RequestBody OrderDto orderDto){
        orderService.customSaveOrder(orderDto);
        return Result.success("新建订单成功");

    }

    /**
     * 根据订单状态查询订单
     * @param status
     * @return
     */
    @GetMapping("/status/{status}")
    public Result<List<Orders>> getByStatus(@PathVariable Integer status){
        List<Orders> ordersList = orderService.getByStatus(status);


        return Result.success(ordersList);

    }


    /**
     * 更新订单
     * @param orders
     * @return
     */
    @PutMapping
    public Result updateOrders(@RequestBody Orders orders){

        orderService.updateById(orders);
        return  Result.success("更新订单成功");


    }


}
